<template>
	<view class="content">
		<view class="ipts">
			<view class="info-item">
				<view class="dot"></view>
				<span>预约编号</span>
				<input v-model="userinfo.no" type="text" disabled placeholder-class="place-class">
			</view>
			<view class="info-item">
				<view class="dot"></view>
				<span>用户</span>
				<input type="text" v-model="userinfo.realname" disabled placeholder-class="place-class">
			</view>

			<view class="info-item">
				<view class="info-item-left">
					<view class="dot"></view>
					<span>预约日期</span>
				</view>
				<text style="color: #333333;">{{userinfo.time}}</text>
			</view>
			<view class="info-item">
				<view class="dot"></view>
				<span>预约事项</span>
				<input disabled v-model="userinfo.category_name" type="text" placeholder-class="place-class">
			</view>
			<view class="info-item">
				<view class="dot"></view>
				<span>电话</span>
				<input @tap="call(userinfo.mobile)" disabled v-model="userinfo.mobile" type="text"
					placeholder-class="place-class">
			</view>
			<view class="info-item">
				<view class="dot"></view>
				<span>身份证号</span>
				<input disabled v-model="userinfo.ID_num" type="text" placeholder-class="place-class">
			</view>
			<view class="info-item">
				<view class="dot"></view>
				<span>地址</span>
				<input disabled v-model="userinfo.address" type="text" placeholder-class="place-class">
			</view>
		
			<!-- 处理情况 -->
			<view class="handle">
				<view class="handle-item">
					<view class="dot"></view>
					<text>预约描述</text>
				</view>
				<textarea :disabled="disabled" v-model="userinfo.remark" type="text" placeholder="预约描述"
					placeholder-class="place-class" />
			</view>
			
			<view class="info-item">
				<view class="info-item-left">
					<view class="dot"></view>
					<span>预约照片</span>
				</view>
				<view class="contimg">
					<template v-for="i,index in userinfo.pic">
						<view :key="index" class="danger-img">
							<image :src="i" mode="" @tap="seeimg(userinfo.pic,index)"></image>
						</view>
					</template>
				</view>
			</view>
		</view>
		<!-- 处理情况 -->
		<view class="handle">
			<view class="handle-item">
				<view class="dot"></view>
				<text>处理情况</text>
			</view>
			<textarea :disabled="disabled" v-model="handel_msg" type="text" placeholder="请输入处理情况"
				placeholder-class="place-class" />
		</view>
		<view class="uploadform">
			<view class="title">
				<text class="point"></text>
				<text class="item-title">完成照片</text>
			</view>
			<view class="addform-items">
				<view class="" style="position: relative;" v-for="(i,index) in image">
					<image class="form-img" :src="i" :key="index" @tap="seeimg(image,index)"></image>
					<image class="delet" v-if="userinfo.check_status == '0'||userinfo.check_status=='3'"
						src="/static/delet.png" mode="" @tap="deletImg('image',index)">
					</image>
				</view>
				<view class="add" @tap="choosefrom('image')"
					v-if="userinfo.check_status == '0'||userinfo.check_status=='3'">
					<u-icon name="camera" color="#999999" size="28"></u-icon>
				</view>
			</view>
		</view>
		<!-- <view class="btn">立即登录</view> -->
		<view class="btns" v-if="userinfo.check_status == '0'||userinfo.check_status=='3'">
			<view class="btn1 consel" @click="handleSubmint1">取消</view>
			<view class="btn1 save" @click="handleSubmint">完成工单</view>
		</view>
		<cpimg ref="cpimg" @result="cpimgOk" @err="cpimgErr" :number="1" :fixOrientation="true" :size="500"
			:maxWidth="800" :ql="0.7" type="url" />

	</view>
</template>

<script>
	export default {

		data() {
			return {
				isChecked: true,
				img1: null, //处理照片的路径
				showR: true,
				username: '',
				password: '',
				// array: ['安装工','检测工','维修工'],
				index: 0,
				userinfo: {},
				value: '', //搜索关键词
				installList: [], //安装列表
				dosearch: false,
				showAcount: false,
				dangerId: '',
				handleText: '',
				fileImg: '',
				long: '',
				lat: '',
				instalrets: '',
				image: [],
				noUrlImg: [],
				handel_msg: '',
				disabled: false
			};
		},

		onLoad(option) {
			this.dangerId = option.id
			this.getInstallDetail()
		},
		onShow() {},
		methods: {
			call(num) {
				uni.makePhoneCall({
					phoneNumber: num
				})
			},
			choosefrom(imgs) {
				if (this[imgs].length < 4) {
					var _this = this
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							uni.uploadFile({
								url: _this.$fileImg + '/common/upload',
								filePath: res.tempFilePaths[0],
								name: 'file',
								header: {
									token: uni.getStorageSync('token')
								},
								success: (uploadFileRes) => {
									if (JSON.parse(uploadFileRes.data).code == 1) {
										this[imgs].push(JSON.parse(uploadFileRes.data).data
											.intact_url)
										this.noUrlImg.push(JSON.parse(uploadFileRes.data).data.url)
									}
								},
								fail: (err) => {
									console.log(err);
								}
							})
						}
					})
				} else {
					this.$showToast('上传已达到限制')
				}
			},
			//图片预览
			seeimg(img, index = 0) {
				uni.previewImage({
					urls: img,
					current: index
				})
			},

			// 选择气表照片

			changeImg(ret) {
				var that = this;
				that.$refs.cpimg._changImg()

			},
			cpimgOk(file) {
				let that = this
				uni.showLoading({
					title: '上传中...'
				})

				// 上传图片
				uni.uploadFile({
					// url:'https://trq.aoaojiao.online/api/common/upload',
					url: that.$fileImg + '/common/upload',
					filePath: file[0],
					name: 'file',
					formData: {
						token: uni.getStorageSync('token'),
						no_water: 1
					},
					success(res1) {
						let dataPath = JSON.parse(res1.data)
						if (dataPath.code == 1) {
							that.fileImg = dataPath.data.url
							that.img1 = file[0]
						}

						uni.hideLoading()
					},
					fail: () => {
						uni.hideLoading()
						uni.showToast({
							title: '上传失败'
						})
					}
				});

			},

			tapMap(lat, long) {
				uni.navigateTo({
					url: '/pages/safety/maps/maps?lat=' + lat + '&long=' + long
				})
			},
			//获取地理位置
			getMap() {
				let that = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						that.long = res.longitude
						that.lat = res.latitude
					}
				});
			},
			// 获取安装数据
			getInstallDetail() {
				let that = this
				that.$request.request({
					url: 'staff/YuyueDetail',
					method: 'POST',
					data: {
						token: uni.getStorageSync('token'),
						yuyeid: that.dangerId
					}
				}).then(res => {
					if (res.data.code == 1) {
						that.userinfo = res.data.data
						that.handel_msg = res.data.data.handel_msg
						that.image = res.data.data.handel_picture
						that.noUrlImg = res.data.data.handel_pictureurl
						that.disabled = that.userinfo.check_status == '1' || that.userinfo.check_status == '2'
					}
				})
			},
			// 删除图片
			deletImg(img, index) {
				this[img].splice(index, 1)
				this.noUrlImg.splice(index, 1)
			},
			handleSubmint1() {
				uni.navigateBack({
					delta: 1
				})
			},
			handleSubmint() {
				let that = this
				if (!this.handel_msg) return this.$showToast('请输入处理情况')
				if (that.image.length < 1) {
					uni.showToast({
						title: '请上传处理照片',
						icon: 'none'
					})
					return
				}
				that.$request.request({
					url: 'staff/submitYuyue',
					method: 'POST',
					data: {
						yuyeid: that.dangerId,
						token: uni.getStorageSync('token'),
						handel_picture: that.noUrlImg.toString(),
						handel_msg: that.handel_msg
					}
				}).then(res => {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
					if (res.data.code == 1) {
						setTimeout(() => {
							uni.navigateBack({
								delta: res
							})
						}, 1000)
					}
				})
			}
		},

	}
</script>

<style lang="scss" scoped>
	.content {
		position: relative;
		padding-bottom: 140rpx;
		background: #FFFFFF;
	}

	.uploadform {
		display: flex;
		align-items: center;
		padding: 22rpx 32rpx;
		justify-content: space-between;
		border-bottom: 1rpx solid #DDDDDD;

		.title {
			display: flex;
			align-items: center;

			.point {
				width: 8rpx;
				height: 8rpx;
				background: #003690;
				border-radius: 50%;
				margin-right: 14rpx;
			}

			.item-title {
				font-size: 28rpx;
				font-family: Source Han Sans SC;
				font-weight: 400;
				color: #333333;
			}
		}

		.addform-items {
			display: flex;
			align-items: center;

			.delet {
				position: absolute;
				top: -8rpx;
				right: 4rpx;
				width: 28rpx;
				height: 28rpx;
				z-index: 10;
			}

			.form-img {
				width: 60rpx;
				height: 60rpx;
				margin-right: 20rpx;
			}

			.form-file {
				width: 50rpx;
				height: 60rpx;
				margin-right: 20rpx;
			}

			.add {
				width: 60rpx;
				height: 60rpx;
				border: 1rpx solid #DDDDDD;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.item-ipt {
			width: 400rpx;
			text-align: end;
		}
	}

	.uni-input {
		padding: 0;
	}

	.contimg {
		display: flex;
	}

	// header
	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 30rpx;
		background-color: #fff;

		.header-left {
			display: flex;
			align-items: center;
			font-size: 32rpx;
			font-weight: 500;
			color: #333;

			image {
				width: 24rpx;
				height: 24rpx;
				margin-right: 20rpx;
			}
		}

		.header-right {
			display: flex;
			align-items: center;
			font-size: 24rpx;
			color: #333;

			image {
				width: 52rpx;
				height: 52rpx;
				margin-right: 10rpx;
			}
		}
	}

	.ipts {
		background-color: #fff;
		margin-top: 30rpx;
	}

	.info-item {
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		// height: 72rpx;
		width: 100%;
		padding: 0rpx 32rpx;
		height: 100rpx;
		align-items: center;
		background-color: #fff;
		font-size: 28rpx;
		color: #333;
		border-bottom: 1rpx solid #DDDDDD;

		input {
			flex: 1;
			text-align: right;
			color: #333333;
			font-size: 28rpx;
		}

		.dot {
			width: 8rpx;
			height: 8rpx;
			background-color: #003690;
			border-radius: 50%;
			margin-right: 10rpx;
		}

		.danger-img {
			position: relative;
			width: 75rpx;
			height: 75rpx;
			border: 2rpx dashed #eee;
			margin-right: 10rpx;

			image {
				width: 100%;
				height: 100%;
			}

			.delet {
				position: absolute;
				top: -12rpx;
				right: -12rpx;
				width: 24rpx;
				height: 24rpx;
				z-index: 999;
			}
		}

		.danger-img-box {
			display: flex;
		}

		.info-item-left {
			display: flex;
			align-items: center;
			font-size: 28rpx;
		}
	}

	.hengxian {
		width: 700rpx;
		height: 2rpx;
		background-color: #eee;
		margin: 20rpx auto;
	}

	.place-class {
		font-size: 26rpx;
		color: #999;
	}

	.btn {
		width: 646rpx;
		height: 80rpx;
		margin: 74rpx auto;
		text-align: center;
		line-height: 80rpx;
		border-radius: 40rpx;
		background-image: linear-gradient(to bottom, #2366D5, #001B48);
		font-size: 32rpx;
		color: #E5EFFE;
	}

	.btns {
		position: fixed;
		bottom: 0;
		display: flex;
		width: 100%;

		.btn1 {
			width: 50%;
			height: 96rpx;
			line-height: 96rpx;
			text-align: center;
			font-size: 24rpx;
		}

		.consel {
			background-color: #e9e9e9;
			color: #777;
		}

		.save {
			background-color: #003690;
			color: #fff;
		}
	}

	.btn:active {
		background: rgba(0, 0, 0, 0.4);
	}

	.record {
		display: flex;
		align-items: center;
		color: #003690;
		font-size: 24rpx;
		margin-top: 20rpx;

		image {
			width: 32rpx;
			height: 32rpx;
			margin: 0 20rpx 0 30rpx;
		}

		span {
			font-weight: 700;
		}
	}

	.record-item {
		display: flex;
		justify-content: space-between;
		padding: 10rpx 30rpx;
		border-bottom: 2rpx solid #eee;

		.record-item-left {
			display: flex;
			align-items: center;

			.shu {
				width: 8rpx;
				height: 28rpx;
				background-color: #003690;
				border-radius: 8rpx;
			}

			.title {
				font-size: 32rpx;
				color: #333;
				font-weight: 500;
				margin: 0 10rpx;
			}

			.time {
				font-size: 24rpx;
				color: #777;
			}
		}

		.record-item-right {
			display: flex;
			align-items: center;

			.dianhua {
				width: 28rpx;
				height: 28rpx;
			}

			.zhankai {
				width: 36rpx;
				height: 36rpx;
			}

			.title {
				font-size: 32rpx;
				color: #555;
				font-weight: 500;
				margin: 0 10rpx;
			}
		}
	}

	.handle {
		box-sizing: border-box;
		display: grid;
		grid-template-columns: 150rpx auto;
		align-items: center;
		// height: 72rpx;
		width: 100%;
		padding: 32rpx 32rpx;
		align-items: center;
		background-color: #fff;
		font-size: 28rpx;
		color: #333;
		border-bottom: 1rpx solid #DDDDDD;
		word-break: break-all;

		.handle-item {
			display: flex;
			align-items: center;
		}

		.handle-text {
			// flex: 1;
			word-break: break-all;
			word-wrap: break-word;
			text-align: right;
			color: #333333;
			font-size: 28rpx;
		}

		.dot {
			width: 8rpx;
			height: 8rpx;
			background-color: #003690;
			border-radius: 50%;
			margin-right: 10rpx;
		}

		textarea {
			width: 550rpx;
		}
	}
</style>
